Passed
Pull Request — master (#163)
by Alejandro
06:15
created

ErrorHandler.js ➔ componentDidCatch   A

Complexity

Conditions 2

Size

Total Lines 4
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 2.5

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 4
ccs 1
cts 2
cp 0.5
rs 10
c 0
b 0
f 0
cc 2
crap 2.5
1
import React from 'react';
2
import * as PropTypes from 'prop-types';
3
import './ErrorHandler.scss';
4
import { Button } from 'reactstrap';
5
6 2
const ErrorHandler = ({ location }, { error }) => class ErrorHandler extends React.Component {
7 2
  static propTypes = {
8
    children: PropTypes.node.isRequired,
9
  };
10
11
  constructor(props) {
12 2
    super(props);
13 2
    this.state = { hasError: false };
14
  }
15
16
  static getDerivedStateFromError() {
17
    return { hasError: true };
18
  }
19
20
  componentDidCatch(e) {
21 2
    if (process.env.NODE_ENV !== 'development') {
22
      error(e);
23
    }
24
  }
25
26
  render() {
27 3
    if (this.state.hasError) {
28 1
      return (
29
        <div className="error-handler">
30
          <h1>Oops! This is awkward :S</h1>
31
          <p>It seems that something went wrong. Try refreshing the page or just click this button.</p>
32
          <br />
33
          <Button outline color="primary" onClick={() => location.reload()}>Take me back</Button>
34
        </div>
35
      );
36
    }
37
38 2
    return this.props.children;
39
  }
40
};
41
42
export default ErrorHandler;
43